<!--
 * Description: rd-gcm映射新增页面
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Qiuxue.Wu
 * Date: 2020/05/28 13:32
-->

<template>
  <div>
    <!--数据表单-->
    <el-form label-width="120px" :model="formData" size="mini">
      <el-row>
        <!--RD Function--->
        <el-col :span="24">
          <el-form-item :label="$t('RdGcmMap.rdFunction')">
            <el-select
              v-model="formData.rdFunction"
              clearable
              filterable
              :placeholder="$t('select.placeholder')"
            >
              <el-option
                v-for="item in $store.getters['enums/getRdFunctionList']"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
        </el-col>

        <!--Category-->
        <el-col :span="24">
          <el-form-item :label="$t('RdGcmMap.category')">
            <el-select
              v-model="formData.category"
              clearable
              filterable
              :placeholder="$t('select.placeholder')"
            >
              <el-option
                v-for="item in $store.getters['category/getCategoryCollects']"
                :key="item.name"
                :label="item.name"
                :value="item.name"
              />
            </el-select>
          </el-form-item>
        </el-col>

        <!--GCM Function-->
        <el-col :span="24">
          <el-form-item :label="$t('RdGcmMap.gcmFunction')">
            <el-select
              v-model="formData.gcmFunction"
              clearable
              filterable
              :placeholder="$t('select.placeholder')"
            >
              <el-option
                v-for="item in $store.getters['enums/getGcmFunctionListOnly']"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span style="display: block;text-align: center;margin-top: 5px">
      <!--取消按钮-->
      <el-button size="medium" @click="cancel">{{ $t('button.cancel') }}</el-button>
      <!--保存按钮-->
      <el-button :loading="isRequesting" size="medium" type="primary" @click="save">
        {{ $t('button.save') }}
      </el-button>
    </span>
  </div>
</template>

<script>
import { rdGcmAdd } from '@/api/quote/rd-gcm'
export default {
  name: 'RdGcmMapAdd',
  data() {
    return {
      // 正在查询
      isRequesting: false,
      formData: {
        category: '',
        gcmFunction: '',
        rdFunction: ''
      }
    }
  },
  methods: {
    async save() {
      try {
        this.isRequesting = true
        await rdGcmAdd(
          {
            category: this.formData.category,
            gcmFunction: this.formData.gcmFunction,
            rdFunction: this.formData.rdFunction
          },
          { msgSuccess: true, msgError: true }
        )
        this.$emit('save')
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    cancel() {
      this.$emit('cancel')
    }
  }
}
</script>

<style></style>
